import { createStore, applyMiddleware } from "redux"
import thunk from "redux-thunk"
import logger from "redux-logger"
import { ACTION, STOREITEM } from "../type/store"
// import { useNavigate } from "react-router"

const initialState = {
    getUserData: {}
}

const reducer = (state: STOREITEM = initialState, { type, payload }: ACTION) => {
    switch (type) {

        case "NUM":
            return { ...state, ...payload }
        case "GET_YSER_DATA":
            console.log(payload)
            localStorage.setItem("user", JSON.stringify(payload))
            state.getUserData = payload
            return { ...state, ...state.getUserData }
        default:
            return state
    }
}

const store = createStore(reducer, applyMiddleware(thunk, logger))
export default store


